<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

session_start();

require_once 'includes/connect.php';
require_once 'includes/function.php';

$task = $_REQUEST["task"];

$db = new myDBS();

$debtor_id = $_REQUEST["debtor_id"];
$debtor_name = $_REQUEST["debtor_name"];
$debtor_group_id = $_REQUEST["debtor_group_id"];
$card_id = $_REQUEST["card_id"];
$addr = $_REQUEST["addr"];
$tel = $_REQUEST["tel"];
$refference_id = $_REQUEST["refference_id"];
$e1 = $_REQUEST["e1"];


switch ($task) {
    case "new":
        
        if ($debtor_name == "") {
            $debtor_name =  $e1;
        }
        
        $sql = "INSERT INTO tbl_debtor (debtor_name, debtor_group_id, card_id, addr, tel, refference_id)"
                . " VALUES ('$debtor_name', '$debtor_group_id', '$card_id', '$addr', '$tel', '$refference_id' )";

        //echo $sql;
        $db->runSQL($sql) or die(mysql_error());
        break;
    case "edit":
        if ($debtor_name == "") {
            $debtor_name =  $e1;
        }
        $sql = "UPDATE tbl_debtor "
                . " SET debtor_name = '$debtor_name' "
                . " , debtor_group_id = '$debtor_group_id' "
                . " , card_id = '$card_id' "
                . " , addr = '$addr' "
                . " , tel = '$tel' "
                . " , refference_id = '$refference_id' "
                . " WHERE debtor_id = '$debtor_id'";

        $db->runSQL($sql) or die(mysql_error());
        break;
    case "del":

        $sql = "DELETE FROM tbl_debtor "
                . " WHERE debtor_id = '$debtor_id'";

        $db->runSQL($sql) or die(mysql_error());
        break;
}
?>

